// import { nodeFrame } from 'three/examples/jsm/renderers/webgl/nodes/WebGLNodes.js';
// import * as Nodes from 'three/examples/jsm/renderers/nodes/Nodes.js';

function huoYan(firetorch_1) {
	
	const huoGeo = new THREE.BoxGeometry(0.2, 0.01, 0.7, 4, 1, 10);
	const sphereGeometry = new THREE.SphereGeometry(50, 130, 16);
	
	const geometry = new THREE.BufferGeometry();
	
	// buffers
	
	const speed = [];
	const intensity = [];
	const size = [];
	
	const positionAttribute = huoGeo.getAttribute('position');
	const particleCount = positionAttribute.count;
	
	for (let i = 0; i < particleCount; i++) {
	
		speed.push(20 + Math.random() * 50);
	
		intensity.push(Math.random() * .15);
	
		size.push(0.5 + Math.random() * 1);
	
	}
	
	geometry.setAttribute('position', positionAttribute);
	geometry.setAttribute('targetPosition', sphereGeometry.getAttribute('position'));
	geometry.setAttribute('particleSpeed', new THREE.Float32BufferAttribute(speed, 1));
	geometry.setAttribute('particleIntensity', new THREE.Float32BufferAttribute(intensity, 1));
	geometry.setAttribute('particleSize', new THREE.Float32BufferAttribute(size, 1));
	
	// maps
	
	// Forked from: https://answers.unrealengine.com/questions/143267/emergency-need-help-with-fire-fx-weird-loop.html
	
	const fireMap = firetorch_1;
	
	// nodes
	
	const targetPosition = new Nodes.AttributeNode('targetPosition', 'vec3');
	const particleSpeed = new Nodes.AttributeNode('particleSpeed', 'float');
	const particleIntensity = new Nodes.AttributeNode('particleIntensity', 'float');
	const particleSize = new Nodes.AttributeNode('particleSize', 'float');
	
	const time = new Nodes.TimerNode();
	
	const spriteSheetCount = new Nodes.Vector2Node(new THREE.Vector2(6, 6)).setConst(true);
	
	const fireUV = new Nodes.SpriteSheetUVNode(
		spriteSheetCount, // count
		new Nodes.PointUVNode(), // uv
		new Nodes.OperatorNode('*', time, particleSpeed) // current frame
	);
	
	const fireSprite = new Nodes.TextureNode(fireMap, fireUV);
	const fire = new Nodes.OperatorNode('*', fireSprite, particleIntensity);
	
	const lerpPosition = new Nodes.FloatNode(0);
	
	const positionNode = new Nodes.MathNode(Nodes.MathNode.MIX, new Nodes.PositionNode(Nodes.PositionNode.LOCAL),
		targetPosition, lerpPosition);
	
	// material
	
	const material = new Nodes.PointsNodeMaterial({
		depthWrite: false,
		transparent: true,
		sizeAttenuation: true,
		blending: THREE.AdditiveBlending
	});
	
	material.colorNode = fire;
	material.sizeNode = particleSize;
	material.positionNode = positionNode;
	
	const particles = new THREE.Points(geometry, material);
	
	return particles;
}

export {
	// nodeFrame,
	huoYan
}